<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.*"%>
<%@page import="com.dss.service.ExpertService"%>
<%@page import="com.dss.po.ExpertDoc"%>
<%  response.addDateHeader("Expires", 0);response.setHeader("Pragma","no-cache"); response.setHeader("Cache-Control","no-cache");%>
<%
    request.setCharacterEncoding("UTF-8");
	String expertId = request.getParameter("expertId");
	String itemId = request.getParameter("expertDocId");
    if(itemId == null) itemId = "";
    boolean isEditMode = "".equals(itemId) ? false : true;
    ExpertDoc doc = ExpertService.loadDocById(request, response, out);
    String name = "";
    String storeName = "";
    String keywords = "";
    String summary = "";
    String expertDocId = "";
    if(doc != null){
    	name = doc.getName();
    	storeName = doc.getStoreName();
    	keywords = doc.getKeywords();
    	summary = doc.getSummary();
    	expertDocId = String.valueOf(doc.getExpertDocId());
    }
%>
<html>
<head>
	<title>专家文档</title>
	<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
	<link href="../../css/table.css" rel="stylesheet" type="text/css">
	<script type="text/javascript">
		function doSubmit(){
			if(!validate()){
				return;
			}
		 	if("" == "<%=itemId%>") {
		 		form1.actionType.value = "add";
			}else {
		 		form1.actionType.value = "modify";
			}
			form1.submit();
		}	

		function validate(){

		    if("" == "<%=itemId%>") {//新增时验证文件类型   	    
				var extend = form1.docName.value.substring(form1.docName.value.lastIndexOf(".")+1);
				    if(extend==""){
				       alert("请上传后缀名为doc、docx或txt的文档!");
				       return false;
				    }else{
					if(!(extend=="doc"||extend=="docx" || extend=="txt")){
					   alert("请上传后缀名为doc、docx或txt的文档!");
					   return false;
					  }
				    }
			}
			
	   		if(form1.name.value == ""){
	   			alert("文档名称不能为空！");
	   			return false;
	   		}

	   		if(form1.keywords.value == ""){
	   			alert("关键字不能为空！");
	   			return false;
	   		}

	   		if(form1.summary.value == ""){
	   			alert("文档摘要不能为空！");
	   			return false;
	   		}

	   		if(form1.summary.value.length > 4000){
   				alert("文档摘要不能超过4000个字！");
   				return false;
	   	    }
	   	    return true;
		}
		
	    function showError(error){
		   alert(error);
	    }

		function showInfo(info){
		   alert(info);
		   window.returnValue = "ok";
		   window.close();
		}
	</script>
</head>
<body rightmargin="0" bottommargin="0" leftmargin="0" topmargin="0">
	<form name="form1" action="expert_doc_action.jsp" method="post" target="actionFrame" enctype='multipart/form-data'>
		<input type="hidden" name="actionType">
		<input type="hidden" name="itemId" value="<%=itemId%>">
		<input type="hidden" name="expertId" value="<%=expertId%>">
		<input type="hidden" name="expertDocId" value="<%=expertDocId %>">
		<table class="dialogTable" cellpadding="0" cellspacing="0"> 
			<!-- 表头-->
			<tr class="dialogTableHeader">
				<td>专家文档</td>
			</tr>
					<!-- 表数据-->
			<tr class="dialogTableContent">
				<td>
					<!-- 数据项 -->
					<table class="dataTable">
						<col width="30%">
						<col width="70%">
						<tr>
							<td class="field">
								文档名称
							</td>
							<td>
								<input value="<%=name %>" name="name" style="width: 100%" type="text">
							</td>
						</tr>
						<tr>
							<td class="field">
								上传
							</td>
							<td>
								<input  value="" name="docName" style="width: 100%" type="file" <%if(isEditMode) out.print("disabled='disabled'"); %>>
							</td>
						</tr>
						<tr>
							<td class="field">
								关键字(用逗号分割)
							</td>
							<td>
								<input value="<%=keywords %>" name="keywords" style="width: 100%" type="text">
							</td>
						</tr>
						<tr style="height: 180px"> 
							<td class="field">
								文档摘要
							</td>
							<td>
								<textarea name="summary" style="width: 100%;height: 100%" ><%=summary %></textarea>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td colspan="2" class="tableBtn">
					<span onclick="doSubmit();">确定</span>
					<span onclick="window.close();">取消</span>
				</td>
			</tr>
			<tr valign="top">
			<td colspan="2">
				&nbsp;
			</td>
		</tr>
		</table>
	</form>
</body>
<iframe src="#" name="actionFrame" style="display: none;"></iframe>
</html>
